'use strict';

const Controller = require('egg').Controller;

class IndexController extends Controller {
  /**
   * 本地图片文字识别
   */
  async localTextIdentify() {
    this.ctx.validate({
      localPath: {
        type: 'string',
      },
    });
    const data = await this.ctx.service.baidu.localTextIdentify();
    this.ctx.sendSuccess(data);
  }
  /**
   * url文字图片识别
   */
  async urlTextIdentify() {
    this.ctx.validate({
      url: {
        type: 'url',
      },
    });
    const data = await this.ctx.service.baidu.urlTextIdentify();
    this.ctx.sendSuccess(data);
  }

  /**
   * 二维码识别
   */
  async qrcodeIdentify() {
    this.ctx.validate({
      localPath: {
        type: 'string',
      },
    });
    const data = await this.ctx.service.baidu.qrcodeIdentify();
    this.ctx.sendSuccess(data);
  }

  /**
   * 身份证识别
   */
  async idcardIdentify() {
    this.ctx.validate({
      localPath: {
        type: 'string',
      },
      isFront: {
        type: 'boolean',
      },
    });
    const data = await this.ctx.service.baidu.idcardIdentify();
    this.ctx.sendSuccess(data);
  }

  /**
   * 银行卡识别
   */
  async bankcardIdentify() {
    this.ctx.validate({
      localPath: {
        type: 'string',
      },
    });
    const data = await this.ctx.service.baidu.bankcardIdentify();
    this.ctx.sendSuccess(data);
  }

  /**
   * 其他文字识别
   */
  async otherIdentify() {
    this.ctx.validate({
      localPath: {
        type: 'string',
      },
      keyName: {
        type: 'string',
      },
    });
    const data = await this.ctx.service.baidu.otherIdentify();
    this.ctx.sendSuccess(data);
  }
}

module.exports = IndexController;
